home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
gui
/
gtlayout.lha
/
Source
/
LTP_DetermineSize.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-09
|
26KB
|
1,076 lines
/*
** GadTools layout toolkit
**
** Copyright © 1993-1998 by Olaf `Olsen' Barthel
** Freely distributable.
**
** :ts=4
*/
#ifndef _GTLAYOUT_GLOBAL_H
#include "gtlayout_global.h"
#endif
#include "Assert.h"
LONG
LTP_GetPickerWidth(
LONG fontHeight,
LONG aspectX,
LONG aspectY)
{
LONG margin,width;
width = (fontHeight * aspectY) / aspectX;
if(width < 8)
width = 8;
margin = 2 + (width + 15) / 16;
return((LONG)(margin + (((115 * width) / 150) & ~1) + 1 + margin));
}
LONG
LTP_GetPickerSize(LayoutHandle *Handle)
{
return(LTP_GetPickerWidth(Handle->TextAttr->ta_YSize,Handle->AspectX,Handle->AspectY));
}
VOID
LTP_DetermineSize(LayoutHandle *Handle,ObjectNode *Node)
{
if(!Handle->Failed)
{
LONG i,Len,Width,Max,Plus;
if(Node->Label)
{
LONG LabelWidth = LT_LabelWidth(Handle,Node->Label);
if(Node->LabelChars * Handle->GlyphWidth > LabelWidth)
LabelWidth = Node->LabelChars * Handle->GlyphWidth;
Node->LabelWidth = LabelWidth;
}
else
Node->LabelWidth = 0;
switch(Node->Type)
{
#ifdef DO_BOOPSI_KIND
{
case BOOPSI_KIND:
if(Node->Special.BOOPSI.ExactWidth)
Node->Width = Node->Special.BOOPSI.ExactWidth;
else
Node->Width = Node->Chars * Handle->GlyphWidth;
if(Node->Special.BOOPSI.ExactHeight)
Node->Height = Node->Special.BOOPSI.ExactHeight;
else
Node->Height = Node->Lines * Handle->GlyphHeight;
if(Node->Special.BOOPSI.RelFontHeight)
Node->Height = Handle->GlyphHeight + Node->Special.BOOPSI.RelFontHeight;
break;
}
#endif /* DO_BOOPSI_KIND */
#ifdef DO_LEVEL_KIND
{
case LEVEL_KIND:
if(Node->Special.Level.Freedom == FREEHORIZ)
{
Node->Width = 6 + Node->Chars * Handle->GlyphWidth + 6;
Node->Height = LTP_QuerySliderSize(Handle->DrawInfo,Handle->GlyphHeight,FREEHORIZ,Node->Special.Level.Ticks);
}
else
{
Node->Height = Node->Lines * Handle->GlyphHeight;
Node->Width = LTP_QuerySliderSize(Handle->DrawInfo,Handle->GlyphHeight,FREEVERT,Node->Special.Level.Ticks);
}
if(Node->DefaultSize && Node->Height < 3 + Handle->GlyphHeight + 3)
Node->Height = 3 + Handle->GlyphHeight + 3;
LTP_GetStorage(Node);
if(Node->Current > Node->Max)
{
Node->Current = Node->Max;
LTP_PutStorage(Node);
}
if(Node->Current < Node->Min)
{
Node->Current = Node->Min;
LTP_PutStorage(Node);
}
if(!Node->Special.Level.MaxLevelWidth || Handle->Rescaled)
{
LTP_LevelWidth(Handle,Node->Special.Level.LevelFormat,Node->Special.Level.DispFunc,Node->Min,Node->Max,&Node->Special.Level.MaxLevelWidth,NULL,Node->Special.Level.FullLevelCheck);
Node->Special.Level.MaxLevelWidth += TextLength(&Handle->RPort," ",1);
}
if(!Node->Special.Level.Plus)
Node->Special.Level.Plus = Node->Min;
if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
if(Node->Special.Level.LevelPlace == PLACETEXT_LEFT &&
Node->LabelPlace == PLACE_LEFT &&
Node->Special.Level.LevelFormat != NULL)
{
Node->LabelWidth += Node->Special.Level.MaxLevelWidth;
}
break;
}
#endif /* DO_LEVEL_KIND */
case GROUP_KIND:
LTP_LayoutGroup(Handle,Node);
break;
case XBAR_KIND:
Node->Width = Handle->GlyphWidth;
Node->Height = 6;
break;
case YBAR_KIND:
Node->Width = 6;
Node->Height = Handle->GlyphHeight;
if(Node->DefaultSize)
Node->Height = 3 + Handle->GlyphHeight + 3;
break;
case IMAGE_KIND:
if(Node->Special.Image.Image != NULL)
{
Node->Width = Node->Special.Image.Image->Width;
Node->Height = Node->Special.Image.Image->Height;
}
else if (Node->Special.Image.BitMap != NULL)
{
Node->Width = Node->Special.Image.BitMapWidth;
Node->Height = Node->Special.Image.BitMapHeight;
}
else
{
Handle->Failed = TRUE;
}
break;
case FRAME_KIND:
{
LONG Width = Node->Special.Frame.InnerWidth;
LONG Height = Node->Special.Frame.InnerHeight;
if(Node->Special.Frame.PlusWidth > 0 || Node->Special.Frame.PlusHeight > 0)
{
Width += Node->Special.Frame.PlusWidth * Handle->GlyphWidth;
Height += Node->Special.Frame.PlusHeight * Handle->GlyphHeight;
}
if(Node->Special.Frame.DrawBox)
{
Node->Width = 4 + Width + 4;
Node->Height = 2 + Height + 2;
}
else
{
Node->Width = Width;
Node->Height = Height;
}
break;
}
case BOX_KIND:
Node->LabelWidth = 0;
if(Node->Special.Box.Labels)
{
for(i = 0 ; i < Node->Lines ; i++)
{
if((Width = TextLength(&Handle->RPort,Node->Special.Box.Labels[i],strlen(Node->Special.Box.Labels[i]))) > Node->LabelWidth)
Node->LabelWidth = Width;
}
}
if(Node->LabelChars)
{
if(Node->LabelChars * Handle->GlyphWidth > Node->LabelWidth)
Node->LabelWidth = Node->LabelChars * Handle->GlyphWidth;
else
Node->LabelWidth = ((Node->LabelWidth + Node->LabelChars - 1) / Node->LabelChars) * Node->LabelChars;
}
Max = Node->Chars;
if(Node->Special.Box.Lines)
{
LONG MaxWidth = 0;
for(i = 0 ; i < Node->Lines ; i++)
{
if(Node->Special.Box.Lines[i])
{
if(Len = strlen(Node->Special.Box.Lines[i]))
{
if((Width = TextLength(&Handle->RPort,Node->Special.Box.Lines[i],Len)) > MaxWidth)
MaxWidth = Width;
}
}
}
if(Max < (MaxWidth + Handle->GlyphWidth - 1) / Handle->GlyphWidth)
Max = (MaxWidth + Handle->GlyphWidth - 1) / Handle->GlyphWidth;
}
Node->Height = 2 + Node->Lines * (Handle->GlyphHeight + Node->Special.Box.Spacing) + 2;
Node->Width = 4 + Max * Handle->GlyphWidth + 4;
if(Node->DefaultSize)
Node->Height = 3 + Node->Lines * (Handle->GlyphHeight + Node->Special.Box.Spacing) + 3;
Node->Height -= Node->Special.Box.Spacing;
break;
case BLANK_KIND:
Node->Width = Handle->GlyphWidth * max(1,Node->Chars);
Node->Height = Handle->GlyphHeight;
Node->Label = "";
Node->LabelWidth = 0;
Node->LabelPlace = PLACE_IN;
if(Node->DefaultSize)
Node->Height = 3 + Handle->GlyphHeight + 3;
break;
case BUTTON_KIND:
if(!Node->Special.Button.Lines && Node->Label)
{
LONG i,Len = strlen(Node->Label),Count = 0;
for(i = 0 ; i < Len ; i++)
{
if(Node->Label[i] == '\n')
Count++;
}
if(Count)
{
STRPTR *Lines;
if(Lines = (STRPTR *)LTP_Alloc(Handle,(Count + 2) * sizeof(STRPTR) + Len + 1))
{
STRPTR String = (STRPTR)(&Lines[Count + 2]);
strcpy(String,Node->Label);
Node->Special.Button.Lines = Lines;
if(Node->Special.Button.KeyStroke)
Node->Special.Button.KeyStroke = &String[((ULONG)Node->Special.Button.KeyStroke) - ((ULONG)Node->Label)];
do
{
*Lines++ = String;
for(i = 0 ; String[i] ; i++)
{
if(String[i] == '\n')
{
String[i] = 0;
String = &String[i + 1];
break;
}
}
}
while(Count--);
}
else
break;
LTP_ReplaceLabelShortcut(Handle,Node);
}
}
if(Node->Special.Button.Lines)
{
STRPTR *Index = Node->Special.Button.Lines;
LONG Count = 0,Width,MaxWidth = 0,Height;
while(*Index)
{
Count++;
if((Width = LT_LabelWidth(Handle,*Index)) > MaxWidth)
MaxWidth = Width;
Index++;
}
Node->Special.Button.LineCount = Count;
if(Node->Chars * Handle->GlyphWidth > MaxWidth)
MaxWidth = Node->Chars * Handle->GlyphWidth;
if(Node->Lines > Count)
Count = Node->Lines;
Height = Count * Handle->GlyphHeight;
if(Node->Special.Button.ExtraFat)
{
Node->Width = 6 + Handle->GlyphWidth + MaxWidth + Handle->GlyphWidth + 6;
Node->Height = 2 + (2 * Height + Handle->GlyphHeight) / 2 + 2;
}
else
{
if(Node->Special.Button.Smaller)
{
Node->Width = 4 + MaxWidt